package com.hctforgreen.greenservice.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.hctforgreen.greenservice.R;
import com.hctforgreen.greenservice.model.PwdEntity;
import com.hctforgreen.greenservice.model.SetupInfoEntity;

/**
 * 安装信息适配器
 * 
 * @author dhb 20150506
 * 
 */
@SuppressLint("ResourceAsColor")
public class SetupInfoListAdapter extends BaseAdapter {
	private List<SetupInfoEntity> pwd_list = new ArrayList<SetupInfoEntity>();

	private LayoutInflater mInflater;
	private Context context;
	public boolean isEdit = false;

	public SetupInfoListAdapter(Context context, List<SetupInfoEntity> pwd_list) {
		super();
		// TODO Auto-generated constructor stub
		this.context = context;
		this.mInflater = LayoutInflater.from(context);
		this.pwd_list = pwd_list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return pwd_list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_his_list_view, null);
			holder.date_txt = (TextView) convertView
					.findViewById(R.id.date_txt);
			holder.del_btn = (Button) convertView.findViewById(R.id.del_btn);
			holder.mark_txt = (TextView) convertView
					.findViewById(R.id.mark_txt);
			holder.pro_name_txt = (TextView) convertView
					.findViewById(R.id.pro_name_txt);
			holder.owner_name_txt = (TextView) convertView
					.findViewById(R.id.owner_name_txt);
			holder.qr_code_txt = (TextView) convertView
					.findViewById(R.id.qr_code_txt);
			holder.pwd_txt = (TextView) convertView.findViewById(R.id.pwd_txt);

			holder.owner_phone_txt = (TextView) convertView
					.findViewById(R.id.tv_owner_phone);

			holder.industry_txt = (TextView) convertView
					.findViewById(R.id.tv_industry);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		// holder.del_btn.setTag(position);
		holder.del_btn.setVisibility(View.GONE);
		SetupInfoEntity entity = pwd_list.get(position);
		holder.date_txt.setText(entity.searchDate);
		holder.mark_txt.setText("备注：" + entity.remark);
		holder.pro_name_txt.setText("工程名：" + entity.projectName);
		holder.owner_name_txt.setText("业主姓名：" + entity.owner);
		holder.qr_code_txt.setText("机型：" + entity.machine);
		// holder.pwd_txt.setText("密码：" + entity.openPassword);
		holder.pwd_txt.setVisibility(View.GONE);
		// holder.owner_phone_txt.setText("联系电话：" + entity.ownerPhone);
		holder.owner_phone_txt.setVisibility(View.GONE);
		holder.industry_txt.setText("安装行业：" + entity.industry);

		return convertView;
	}

	static class ViewHolder {
		TextView date_txt;
		Button del_btn;
		TextView mark_txt;
		TextView pro_name_txt;
		TextView owner_name_txt;
		TextView qr_code_txt;
		TextView pwd_txt;
		TextView owner_phone_txt;
		TextView industry_txt;
	}

}
